from django.db import models


# Create your models here.
from user.models import UserProfile


class Notice(models.Model):
    id = models.AutoField("ID", primary_key=True)
    title = models.CharField(max_length=50, verbose_name="公告标题")
    introduce = models.CharField(max_length=90, verbose_name="公告简介", default="进来看看吧")
    content = models.TextField(verbose_name="公告内容")
    created_time = models.DateTimeField(auto_now_add=True)
    updated_time = models.DateTimeField(auto_now=True)
    click_count = models.IntegerField(verbose_name="点击量", default=0)
    recommend = models.SmallIntegerField(verbose_name='推荐值', default=0)
    author = models.ForeignKey(UserProfile, on_delete=models.CASCADE, null=True, blank=True, default=None)

    # author1 = models.ManyToManyField(UserProfile,through=message.models.Message)

    class Meta:
        verbose_name = "公告"
        verbose_name_plural = "公告"
        db_table = 'notice'
        ordering = ['-recommend', '-created_time']

    def __str__(self):
        return self.title
